/*
 * Created by JFormDesigner on Thu May 20 15:31:01 CST 2021
 */

package com.dfrz.bookstore.view;

import com.dfrz.bookstore.entry.*;
import com.dfrz.bookstore.service.BookTypeService;
import com.dfrz.bookstore.service.impl.*;
import com.dfrz.bookstore.util.InputDataUtile;
import com.dfrz.bookstore.util.OutputDataUtile;


import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;


/**
 * @author Brainrain
 */
public class AdminJFrame extends JFrame {
//    public static AdminJFrame adminJFrame ;
    AdminServiceImpl adminService = new AdminServiceImpl();
    BookServiceImpl bookService = new BookServiceImpl();
    OrderServiceImpl orderService = new OrderServiceImpl();
    IdeaServiceImpl ideaService = new IdeaServiceImpl();
    UserServiceImpl userService = new UserServiceImpl();
    BookTypeService typeService = new BookTypeServiceImpl();
    List<JPanel> jPanelList = new ArrayList<>();//存储首页的图书框
    Admin admin ;//当前管理员
    Book book ;//当前图书
    User user = new User();//默认表示所有用户
    List<Book> bookList ;
    public AdminJFrame(Admin admin, Book book) {
        initComponents();
        this.book = book;
        this.admin = admin;
        setTitle("管理员界面" );
//        ============默认所有首页图书展示===============================
        showBookList(book,1);

//        ============默认所有用户订单展示===============================
        Order order = new Order();
        showOrder(order);
//        ============默认所有用户订单展示===============================
        showIdea();
//        ============默认显示所有用户===============================
        showUser();
//        ============默认显示图书类别===============================
        showType();
        //增加刷新按钮事件
        F5.addActionListener(e -> F5ActionPerformed(e,1));
        F6.addActionListener(e -> F5ActionPerformed(e,4));
        F7.addActionListener(e -> F5ActionPerformed(e,0));
        F8.addActionListener(e -> F5ActionPerformed(e,2));
        delUser.addActionListener(e -> delUserActionPerformed(e));
    }

    private void showType(){
        //查找图书类别不需要传参
        List<BookType> typeList = typeService.findAllBookType();
        String[] title = new String[]{"类型ID","类型"};
        Object[][] types = new Object[typeList.size()][title.length];
        for (int i = 0; i < typeList.size() ; i++) {
            BookType type = typeList.get(i);
            Object[] objects = new Object[]{type.getId(),type.getType()};
            types[i] = objects;
        }

        //---- typeTable ----
        typeTable.setModel(new DefaultTableModel(types,title));
        scrollPane5.setViewportView(typeTable);
    }

    private void showUser(){
        User user = new User();
        List<User> userList = userService.findUserByUser(user);
        String[] title = {"id", "登录名", "密码", "姓名", "性别", "邮箱", "电话号码", "用户等级", "收货地址"};
        Object[][] objects = new Object[userList.size()][title.length];
        for (int i = 0; i < userList.size(); i++) {
            user = userList.get(i);
            Object[] objects1 = new Object[]{user.getId(),user.getLoginName(),user.getPassWord(),user.getName(),user.getSex(),user.getEmail(),
                    user.getTel(),user.getLevel(),user.getAddress()};
            objects[i] = objects1;
        }

        UserTable.setModel(new DefaultTableModel(objects,title));
        scrollPane2.setViewportView(UserTable);
        UserManage.add(scrollPane2);
    }


    /**
     * 用户意见
     */
    private void showIdea(){
        Idea idea = new Idea();
        String[] s = new String[]{"ID","标题","内容","发送时间","用户ID","用户姓名"};
        List<Idea> ideaList = ideaService.findIdeaByIdea(idea);
        Object[][] objects = new Object[ideaList.size()][s.length];

        for (int i = 0; i < ideaList.size(); i++) {
            Idea idea1=ideaList.get(i);
            //获取提交当前订单的用户
            User user = new User();
            user.setId(idea1.getUserId());
            user =  userService.findUserByUser(user).get(0);
            Object[] objects1 = new Object[]{idea1.getId(),idea1.getTitle(),idea1.getContent(),idea1.getSend_time(),user.getId(),user.getName()};
            objects[i]=objects1;
        }
        //---- table3 ----
        table3.setModel(new DefaultTableModel(objects,s));
        scrollPane4.setViewportView(table3);
    }

    /**
     * 订单列表(表格做的)
     */
    JTable table1 ;
    public void showOrder(Order order ){
        ClientPane1.setBackground(new Color(186, 222, 204));
        bookpanel.setBackground(new Color(186, 222, 204, 69));
        showBookJpanel.setBackground(new Color(186, 222, 204, 69));
        String[] titles = {"订单号","订单状态","用户ID","用户姓名"};
        List<Order> orderList = orderService.findOrderByOrder(order);

        Object[][] objects = new Object[orderList.size()][titles.length];

        for (int i=0;i<orderList.size();i++){
            Order order1=orderList.get(i);
            Object[] objects1 = new Object[2];
            int status = order1.getStatus();
            User user1 = new User();
            user1.setId(order1.getUser_id());
            user1 = userService.findUserByUser(user1).get(0);
            if(status==0){
                objects1 = new Object[]{order1.getOrder_item_id(), "未发货",order1.getUser_id(),user1.getName()};
            }else if(status==1){
                objects1 = new Object[]{order1.getOrder_item_id(), "已发货",order1.getUser_id(),user1.getName()};
            }else if(status==2){
                objects1 = new Object[]{order1.getOrder_item_id(), "已收货",order1.getUser_id(),user1.getName()};
            }else if(status==3){
                objects1 = new Object[]{order1.getOrder_item_id(), "已退货",order1.getUser_id(),user1.getName()};
            }

            objects[i]=objects1;
        }


        table1 = new JTable();
        table1.setModel(new DefaultTableModel(objects,titles));
        table1.setSelectionBackground(new Color(0,0,0));
        table1.setRowHeight(30);
        table1.setSelectionForeground(new Color(255,255,255));
        table1.setFont(new Font("黑体", Font.BOLD,20));
        table1.setShowGrid(false);
        /*添加监听事件*/
        table1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                OrderTableMouseClicked(e);
            }
        });
        scrollPane3.setViewportView(table1);
    }

    /**
     * 渲染图书
     * @param book
     * @param pageNum
     */
    public  void showBookList(Book book,int pageNum){
        bookList = bookService.findBookByPage(book, pageNum, 8);
        if (jPanelList.size()>0){
            closeShowBookJpanel();
            repaint();
            showBookJpanel.updateUI();
        }
        /*查找上架的图书总数*/
        int count = bookService.findCount(book,null);
        for (Book book1 : bookList) {
            JPanel jPane_show =  addItem(new JPanel(), book1, showBookJpanel);
            jPanelList.add(jPane_show);
        }
        currentPage.setText(String.valueOf(pageNum));
        int totalPage_ = 0;
        /*计算总页码*/
        if (count%8==0){
            totalPage_ = count/8;
        }else {
            totalPage_ = count/8+1;
        }
        totalPage.setText(String.valueOf(totalPage_));
    }

    /**
     * 清空网格布局里面的数据
     */
    public void closeShowBookJpanel(){
        showBookJpanel.removeAll();
    }

    /**
     * 退出登录
     * @param e
     */
    private void exitButtonActionPerformed(ActionEvent e) {

        int i = JOptionPane.showConfirmDialog(null, "确认退出吗?", "标题", JOptionPane.YES_NO_OPTION);
        if (i==0){
            Login login = new Login();
            login.setVisible(true);
            //关闭客户端
            dispose();
        }
    }

    /**
     *订单表中单击订单 跳转至对应的订单项
     * @param e
     */
    private void OrderTableMouseClicked(MouseEvent e) {
        Object valueAt = table1.getValueAt(table1.getSelectedRow(),0);
        String itemID = (String)valueAt;
        Order order = new Order();
        order.setOrder_item_id(itemID);
        order = orderService.findOrderByOrder(order).get(0);
        OrderItemView orderItemView = new OrderItemView(order,admin);
        orderItemView.setVisible(true);
    }

    /**首页的图书被点击 打开书本详情
     * @param e
     * @param book
     */
    private void itemMouseClicked(MouseEvent e,Book book) {
        BookInfo bookInfo = new BookInfo(book,admin);
        bookInfo.setVisible(true);
    }
    /**
     * 动态添加 窗体 展示图书
     * @param item
     * @param book
     * @param showBookJpanel
     */
    public   JPanel addItem(JPanel item, Book book,JPanel showBookJpanel ){
        //======== item ========
        {
            item.setForeground(new Color(238, 238, 238));
            item.setBackground(UIManager.getColor("Button.default.shadowColor"));
            item.setLayout(null);
            /*添加监听事件*/
            item.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    itemMouseClicked(e,book);
                }
            });

            //---- img ----
            ImageIcon icon = null;
            try {
                icon = new ImageIcon(new URL(book.getImg_src()));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            //改变图片大小
            //80和100为大小 可以自由设置
            icon.setImage(icon.getImage().getScaledInstance(145,180,Image.SCALE_DEFAULT));
            JLabel img = new JLabel();
            img.setIcon(icon);
            item.add(img);
            img.setBounds(39, 10, 145, 180);

            //---- author ----
            JLabel author = new JLabel();
            author.setFont(new Font("方正字迹-叶根友特楷简体", label2.getFont().getStyle(), label2.getFont().getSize() + 2));
            author.setHorizontalAlignment(SwingConstants.CENTER);
            author.setText(book.getAuthor());
            item.add(author);
            author.setBounds(50, 193, 140, author.getPreferredSize().height);

            //---- price ----
            JLabel price = new JLabel();
            price.setFont(new Font("黑体", label2.getFont().getStyle(), label2.getFont().getSize() + 2));
            price.setHorizontalAlignment(SwingConstants.CENTER);
            price.setText(book.getPrice()+"$");
            item.add(price);
            price.setBounds(50, 215,140, 15);

            //---- bookName ----
            JLabel bookName = new JLabel();
            bookName.setFont(new Font("方正字迹-叶根友特楷简体", label2.getFont().getStyle(), label2.getFont().getSize() + 7));
            bookName.setHorizontalAlignment(SwingConstants.CENTER);
            bookName.setText(book.getName());
            item.add(bookName);
            bookName.setBounds(50, 230,140, 15);

            JLabel flagLabel = new JLabel();
            flagLabel.setForeground(new Color(222, 73, 56));
            if (book.getFlag()==0){
                flagLabel.setText("下架");
            }else {
                flagLabel.setText("上架");
            }
            item.add(flagLabel);
            flagLabel.setBounds(150,215,50,15);
            { // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < item.getComponentCount(); i++) {
                    Rectangle bounds = item.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = item.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                item.setMinimumSize(preferredSize);
                item.setPreferredSize(preferredSize);
            }
        }
        showBookJpanel.add(item);
        return item;
    }

    /**
     * 点击上一页
     * @param e
     */
    private void previousPageActionPerformed(ActionEvent e) {
        // TODO add your code here
        if (Integer.valueOf(currentPage.getText())==1){
            JOptionPane.showMessageDialog(null,"当前为第一页");
            return;
        }
        showBookList(book,Integer.valueOf(currentPage.getText())-1);
    }
    /**
     * 点击下一页
     * @param e
     */
    private void nextPageActionPerformed(ActionEvent e) {
        // TODO add your code here
        if (Integer.valueOf(currentPage.getText())==Integer.valueOf(totalPage.getText())){
            JOptionPane.showMessageDialog(null,"当前为最后一页");
            return;
        }
        showBookList(book,Integer.valueOf(currentPage.getText())+1);
    }

    /**跳转第一页
     * @param e
     */
    private void FirstPageActionPerformed(ActionEvent e) {
        // TODO add your code here
        showBookList(book,1);
    }

    /**跳转最后一页
     * @param e
     */
    private void endPageActionPerformed(ActionEvent e) {
        // TODO add your code here
        showBookList(book,Integer.valueOf(totalPage.getText()));
    }

    /**搜索图书
     *
     * @param e
     */
    private void searchActionPerformed(ActionEvent e) {
        // TODO add your code here
        book.setName(searchBar.getText());
        showBookList(book,1);
    }

    /**
     * 用户修改信息
     * @param e
     */
    private void reviseActionPerformed(ActionEvent e) {
        Object userId = UserTable.getValueAt(UserTable.getSelectedRow(), 0);
        User user = new User();
        user.setId((int)userId);
        user = userService.findUserByUser(user).get(0);
        UserRegistration userRegistration = new UserRegistration(user);
        userRegistration.setVisible(true);
    }

    /**管理员删除员工
     *
     * @param e
     */
    private void delUserActionPerformed(ActionEvent e) {
        Object userId = UserTable.getValueAt(UserTable.getSelectedRow(), 0);
        userService.delectUser((int)userId);
        showUser();
    }
    /**
     *刷新按钮
     * @param e
     * @param i
     */
    private void F5ActionPerformed(ActionEvent e,int i) {
        dispose();
        AdminJFrame adminJFrame1 = new AdminJFrame(admin, new Book());
        adminJFrame1.ClientPane1.setSelectedIndex(i);
        adminJFrame1.setVisible(true);
    }

    /**
     * 删除意见
     * @param e
     */
    private void delIdeaActionPerformed(ActionEvent e) {
        Object id = table3.getValueAt(table3.getSelectedRow(), 0);
        ideaService.delectIdea((int)id);
        showIdea();
    }

    private void addBookActionPerformed(ActionEvent e) {
        new addbook().setVisible(true);
        dispose();
    }
    public JTabbedPane getClientPane1(){
        return ClientPane1;
    }

    /**
     * 添加图书类别
     * @param e
     */
    private void addTypeActionPerformed(ActionEvent e) {
        String newType = JOptionPane.showInputDialog("请输入要添加的图书类别名称");
        BookType bookType = new BookType();
        bookType.setType(newType);
        typeService.inertBookType(bookType);
        showType();
    }

    /**
     * 修改选中图书类别
     * @param e
     */
    private void alterTypeActionPerformed(ActionEvent e) {

        Object typeID = null;
        Object typeName = null;
        try {
            typeID = typeTable.getValueAt(typeTable.getSelectedRow(), 0); //获取图书ID
            typeName = typeTable.getValueAt(typeTable.getSelectedRow(), 1);//获取图书名称
            String newType = JOptionPane.showInputDialog(typeName + " 修改为?");
            BookType bookType = new BookType();
            bookType.setId((int)typeID);
            bookType.setType(newType);
            typeService.upDataBookType(bookType);
            showType();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null,"请选择要修改的图书类");

        }
    }

    /**
     * 管理员删除图书类别
     * @param e
     */
    private void delTypeActionPerformed(ActionEvent e) {

        Object typeID = null;
        Object typeName = null;
        try {
            typeID = typeTable.getValueAt(typeTable.getSelectedRow(), 0); //获取图书ID
            typeName = typeTable.getValueAt(typeTable.getSelectedRow(), 1);//获取图书名称
            int i = JOptionPane.showConfirmDialog(null, "确认要删除" + typeName + "吗?", "删除提示", JOptionPane.YES_NO_OPTION);
            if (i == JOptionPane.YES_OPTION){
                typeService.delectBookTypeById((int)typeID);
                showType();//刷新表格
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null,"请选择要删除的图书类");
        }

    }

    /**
     * 批量导入图书
     * @param e
     */
    private void ExlAddBooksActionPerformed(ActionEvent e) {
        JFileChooser fd = new JFileChooser();
        fd.setFileSelectionMode(JFileChooser.OPEN_DIALOG);
        fd.showOpenDialog(null);
        File f = fd.getSelectedFile();
        if (f==null){
            return;
        }
        InputDataUtile.inPutBookInfo(f);
    }
    /**
     * 批量导出图书
     * @param e
     */
    private void ExlPutBooksActionPerformed(ActionEvent e) {
        JFileChooser fd = new JFileChooser();
        fd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fd.showOpenDialog(null);
        File f = fd.getSelectedFile();
        f = new File(f,"bookInfo.xls");
        if (f==null){
            return;
        }
        OutputDataUtile.outBookInfo(bookService.findBookByBook(book),f);

    }
    /**
     * 批量导出订单和订单项
     * @param e
     */
    private void ExlputOedersActionPerformed(ActionEvent e) {

        JFileChooser fd = new JFileChooser();
        fd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fd.showOpenDialog(null);
        File f = fd.getSelectedFile();
        f = new File(f,"orderInfo.xls");
        if (f==null){
            return;
        }
        Order order = new Order();
        OutputDataUtile.outOrderInfo(orderService.findOrderByOrder(order),f);
    }
    /**
     * 批量导出用户
     * @param e
     */
    private void ExlPutUsersActionPerformed(ActionEvent e) {
        JFileChooser fd = new JFileChooser();
        fd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fd.showOpenDialog(null);
        File f = fd.getSelectedFile();
        f = new File(f,"userInfo.xls");
        if (f==null){
            return;
        }
        OutputDataUtile.outUserInfo(userService.findUserByUser(user),f);
    }
    /**
     * 批量导入用户
     * @param e
     */
    private void ExlAddUsersActionPerformed(ActionEvent e) {
        JFileChooser fd = new JFileChooser();
        fd.setFileSelectionMode(JFileChooser.OPEN_DIALOG);
        fd.showOpenDialog(null);
        File f = fd.getSelectedFile();
        if (f==null){
            return;
        }
        InputDataUtile.inPutUserInfo(f);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        ClientPane1 = new JTabbedPane();
        bookpanel = new JPanel();
        showBookJpanel = new JPanel();
        FirstPage = new JButton();
        previousPage = new JButton();
        nextPage = new JButton();
        endPage = new JButton();
        label13 = new JLabel();
        currentPage = new JLabel();
        label2 = new JLabel();
        totalPage = new JLabel();
        label4 = new JLabel();
        searchBar = new JTextField();
        search = new JButton();
        userImg = new JLabel();
        addBook = new JButton();
        F7 = new JButton();
        ExlPutBooks = new JButton();
        ExlAddBooks = new JButton();
        orderpanel = new JPanel();
        scrollPane3 = new JScrollPane();
        F5 = new JButton();
        ExlputOeders = new JButton();
        UserManage = new JPanel();
        exitButton = new JButton();
        revise = new JButton();
        scrollPane2 = new JScrollPane();
        UserTable = new JTable();
        F8 = new JButton();
        delUser = new JButton();
        ExlPutUsers = new JButton();
        ExlAddUsers = new JButton();
        ideapanel = new JPanel();
        delIdea = new JButton();
        scrollPane4 = new JScrollPane();
        table3 = new JTable();
        textArea2 = new JTextArea();
        F6 = new JButton();
        BookTypepanel = new JPanel();
        scrollPane5 = new JScrollPane();
        typeTable = new JTable();
        addType = new JButton();
        alterType = new JButton();
        delType = new JButton();

        //======== this ========
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //======== ClientPane1 ========
        {

            //======== bookpanel ========
            {
                bookpanel.setLayout(null);

                //======== showBookJpanel ========
                {
                    showBookJpanel.setLayout(new GridLayout(2, 4));
                }
                bookpanel.add(showBookJpanel);
                showBookJpanel.setBounds(50, 60, 925, 530);

                //---- FirstPage ----
                FirstPage.setText("\u7b2c\u4e00\u9875");
                FirstPage.addActionListener(e -> FirstPageActionPerformed(e));
                bookpanel.add(FirstPage);
                FirstPage.setBounds(95, 615, FirstPage.getPreferredSize().width, 29);

                //---- previousPage ----
                previousPage.setText("\u4e0a\u4e00\u9875");
                previousPage.addActionListener(e -> previousPageActionPerformed(e));
                bookpanel.add(previousPage);
                previousPage.setBounds(265, 615, 78, 30);

                //---- nextPage ----
                nextPage.setText("\u4e0b\u4e00\u9875");
                nextPage.addActionListener(e -> nextPageActionPerformed(e));
                bookpanel.add(nextPage);
                nextPage.setBounds(660, 610, 78, 30);

                //---- endPage ----
                endPage.setText("\u5c3e\u9875");
                endPage.addActionListener(e -> endPageActionPerformed(e));
                bookpanel.add(endPage);
                endPage.setBounds(850, 610, 78, 30);

                //---- label13 ----
                label13.setText("\u5f53\u524d\u9875:");
                bookpanel.add(label13);
                label13.setBounds(425, 620, 50, label13.getPreferredSize().height);

                //---- currentPage ----
                currentPage.setText("1");
                bookpanel.add(currentPage);
                currentPage.setBounds(490, 620, 30, currentPage.getPreferredSize().height);

                //---- label2 ----
                label2.setText("\u5171");
                bookpanel.add(label2);
                label2.setBounds(new Rectangle(new Point(525, 620), label2.getPreferredSize()));

                //---- totalPage ----
                totalPage.setText("text");
                bookpanel.add(totalPage);
                totalPage.setBounds(new Rectangle(new Point(545, 620), totalPage.getPreferredSize()));

                //---- label4 ----
                label4.setText("\u9875");
                bookpanel.add(label4);
                label4.setBounds(new Rectangle(new Point(575, 620), label4.getPreferredSize()));

                //---- searchBar ----
                searchBar.setText("\u7ea2\u697c\u68a6");
                bookpanel.add(searchBar);
                searchBar.setBounds(320, 10, 370, 35);

                //---- search ----
                search.setText("\u641c\u7d22");
                search.addActionListener(e -> searchActionPerformed(e));
                bookpanel.add(search);
                search.setBounds(new Rectangle(new Point(700, 15), search.getPreferredSize()));
                bookpanel.add(userImg);
                userImg.setBounds(5, 5, 50, 50);

                //---- addBook ----
                addBook.setText("\u6dfb\u52a0\u56fe\u4e66");
                addBook.addActionListener(e -> addBookActionPerformed(e));
                bookpanel.add(addBook);
                addBook.setBounds(new Rectangle(new Point(785, 15), addBook.getPreferredSize()));

                //---- F7 ----
                F7.setText("\u8fd4\u56de");
                bookpanel.add(F7);
                F7.setBounds(230, 10, 78, 30);

                //---- ExlPutBooks ----
                ExlPutBooks.setText("\u6279\u91cf\u5bfc\u51fa");
                ExlPutBooks.addActionListener(e -> ExlPutBooksActionPerformed(e));
                bookpanel.add(ExlPutBooks);
                ExlPutBooks.setBounds(new Rectangle(new Point(950, 15), ExlPutBooks.getPreferredSize()));

                //---- ExlAddBooks ----
                ExlAddBooks.setText("\u6279\u91cf\u5bfc\u5165");
                ExlAddBooks.addActionListener(e -> ExlAddBooksActionPerformed(e));
                bookpanel.add(ExlAddBooks);
                ExlAddBooks.setBounds(new Rectangle(new Point(870, 15), ExlAddBooks.getPreferredSize()));

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < bookpanel.getComponentCount(); i++) {
                        Rectangle bounds = bookpanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = bookpanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    bookpanel.setMinimumSize(preferredSize);
                    bookpanel.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u56fe\u4e66\u7ba1\u7406", bookpanel);

            //======== orderpanel ========
            {
                orderpanel.setLayout(null);
                orderpanel.add(scrollPane3);
                scrollPane3.setBounds(40, 30, 930, 545);

                //---- F5 ----
                F5.setText("\u5237\u65b0");
                orderpanel.add(F5);
                F5.setBounds(new Rectangle(new Point(915, 0), F5.getPreferredSize()));

                //---- ExlputOeders ----
                ExlputOeders.setText("\u6279\u91cf\u5bfc\u51fa");
                ExlputOeders.addActionListener(e -> ExlputOedersActionPerformed(e));
                orderpanel.add(ExlputOeders);
                ExlputOeders.setBounds(new Rectangle(new Point(765, 0), ExlputOeders.getPreferredSize()));

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < orderpanel.getComponentCount(); i++) {
                        Rectangle bounds = orderpanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = orderpanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    orderpanel.setMinimumSize(preferredSize);
                    orderpanel.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u8ba2\u5355\u7ba1\u7406", orderpanel);

            //======== UserManage ========
            {
                UserManage.setLayout(null);

                //---- exitButton ----
                exitButton.setText("\u9000\u51fa\u767b\u5f55");
                exitButton.setFont(exitButton.getFont().deriveFont(exitButton.getFont().getSize() + 20f));
                exitButton.addActionListener(e -> exitButtonActionPerformed(e));
                UserManage.add(exitButton);
                exitButton.setBounds(870, 620, 155, 45);

                //---- revise ----
                revise.setText("\u4fee\u6539\u8d26\u6237");
                revise.setFont(revise.getFont().deriveFont(revise.getFont().getSize() + 20f));
                revise.addActionListener(e -> reviseActionPerformed(e));
                UserManage.add(revise);
                revise.setBounds(865, 30, 135, 50);

                //======== scrollPane2 ========
                {

                    //---- UserTable ----
                    UserTable.setModel(new DefaultTableModel(
                        new Object[][] {
                            {"1", "2", "2", "3", "4", "5", "6", "7", "8"},
                            {null, null, null, null, null, null, null, null, null},
                        },
                        new String[] {
                            null, null, null, null, null, null, null, null, null
                        }
                    ));
                    scrollPane2.setViewportView(UserTable);
                }
                UserManage.add(scrollPane2);
                scrollPane2.setBounds(30, 25, 780, 605);

                //---- F8 ----
                F8.setText("\u5237\u65b0");
                UserManage.add(F8);
                F8.setBounds(875, 250, 125, 35);

                //---- delUser ----
                delUser.setText("\u5220\u9664");
                UserManage.add(delUser);
                delUser.setBounds(875, 145, 125, 35);

                //---- ExlPutUsers ----
                ExlPutUsers.setText("\u6279\u91cf\u5bfc\u51fa");
                ExlPutUsers.addActionListener(e -> ExlPutUsersActionPerformed(e));
                UserManage.add(ExlPutUsers);
                ExlPutUsers.setBounds(885, 375, 115, ExlPutUsers.getPreferredSize().height);

                //---- ExlAddUsers ----
                ExlAddUsers.setText("\u6279\u91cf\u5bfc\u5165");
                ExlAddUsers.addActionListener(e -> ExlAddUsersActionPerformed(e));
                UserManage.add(ExlAddUsers);
                ExlAddUsers.setBounds(885, 435, 115, ExlAddUsers.getPreferredSize().height);

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < UserManage.getComponentCount(); i++) {
                        Rectangle bounds = UserManage.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = UserManage.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    UserManage.setMinimumSize(preferredSize);
                    UserManage.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u7528\u6237\u7ba1\u7406", UserManage);

            //======== ideapanel ========
            {
                ideapanel.setLayout(null);

                //---- delIdea ----
                delIdea.setText("\u5220\u9664\u610f\u89c1");
                delIdea.addActionListener(e -> delIdeaActionPerformed(e));
                ideapanel.add(delIdea);
                delIdea.setBounds(710, 395, 130, 35);

                //======== scrollPane4 ========
                {

                    //---- table3 ----
                    table3.setModel(new DefaultTableModel(
                        new Object[][] {
                            {"1", "1", "1", "1", "1"},
                            {null, null, null, null, null},
                        },
                        new String[] {
                            null, null, null, null, null
                        }
                    ));
                    scrollPane4.setViewportView(table3);
                }
                ideapanel.add(scrollPane4);
                scrollPane4.setBounds(45, 15, 920, 365);
                ideapanel.add(textArea2);
                textArea2.setBounds(new Rectangle(new Point(20, 125), textArea2.getPreferredSize()));

                //---- F6 ----
                F6.setText("\u5237\u65b0");
                ideapanel.add(F6);
                F6.setBounds(880, 395, 90, 35);

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < ideapanel.getComponentCount(); i++) {
                        Rectangle bounds = ideapanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = ideapanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    ideapanel.setMinimumSize(preferredSize);
                    ideapanel.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u610f\u89c1\u53cd\u9988", ideapanel);

            //======== BookTypepanel ========
            {
                BookTypepanel.setLayout(null);

                //======== scrollPane5 ========
                {

                    //---- typeTable ----
                    typeTable.setModel(new DefaultTableModel(
                        new Object[][] {
                            {"1", "1"},
                            {null, null},
                        },
                        new String[] {
                            null, null
                        }
                    ));
                    scrollPane5.setViewportView(typeTable);
                }
                BookTypepanel.add(scrollPane5);
                scrollPane5.setBounds(35, 20, 750, 630);

                //---- addType ----
                addType.setText("\u6dfb\u52a0\u7c7b\u522b");
                addType.addActionListener(e -> addTypeActionPerformed(e));
                BookTypepanel.add(addType);
                addType.setBounds(820, 75, 150, addType.getPreferredSize().height);

                //---- alterType ----
                alterType.setText("\u4fee\u6539\u7c7b\u522b");
                alterType.addActionListener(e -> alterTypeActionPerformed(e));
                BookTypepanel.add(alterType);
                alterType.setBounds(820, 165, 150, 30);

                //---- delType ----
                delType.setText("\u5220\u9664\u7c7b\u522b");
                delType.addActionListener(e -> delTypeActionPerformed(e));
                BookTypepanel.add(delType);
                delType.setBounds(820, 260, 150, 30);

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < BookTypepanel.getComponentCount(); i++) {
                        Rectangle bounds = BookTypepanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = BookTypepanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    BookTypepanel.setMinimumSize(preferredSize);
                    BookTypepanel.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u7c7b\u522b\u7ba1\u7406", BookTypepanel);
        }
        contentPane.add(ClientPane1);
        ClientPane1.setBounds(0, 5, 1035, 715);

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JTabbedPane ClientPane1;
    private JPanel bookpanel;
    private JPanel showBookJpanel;
    private JButton FirstPage;
    private JButton previousPage;
    private JButton nextPage;
    private JButton endPage;
    private JLabel label13;
    private JLabel currentPage;
    private JLabel label2;
    private JLabel totalPage;
    private JLabel label4;
    private JTextField searchBar;
    private JButton search;
    private JLabel userImg;
    private JButton addBook;
    private JButton F7;
    private JButton ExlPutBooks;
    private JButton ExlAddBooks;
    private JPanel orderpanel;
    private JScrollPane scrollPane3;
    private JButton F5;
    private JButton ExlputOeders;
    private JPanel UserManage;
    private JButton exitButton;
    private JButton revise;
    private JScrollPane scrollPane2;
    private JTable UserTable;
    private JButton F8;
    private JButton delUser;
    private JButton ExlPutUsers;
    private JButton ExlAddUsers;
    private JPanel ideapanel;
    private JButton delIdea;
    private JScrollPane scrollPane4;
    private JTable table3;
    private JTextArea textArea2;
    private JButton F6;
    private JPanel BookTypepanel;
    private JScrollPane scrollPane5;
    private JTable typeTable;
    private JButton addType;
    private JButton alterType;
    private JButton delType;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
